package team.szm.scd.controller;

import org.springframework.web.bind.annotation.*;
import team.szm.scd.database.dto.RequestWrapper;
import team.szm.scd.database.dto.Result;
import team.szm.scd.database.entity.Department;
import team.szm.scd.service.interfaces.IDepartmentService;
import team.szm.scd.service.interfaces.ILoginService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Resource
    IDepartmentService service;
    @Resource
    ILoginService loginService;

    @PostMapping("/fromHospital")
    @ResponseBody
    public Result<List<Department>> fromHospital
            (@RequestBody RequestWrapper<Integer> hospitalId, HttpSession session) {
        if (loginService.noUserAndNoDoctorLogin(session)) {
            return Result.needLogin();
        }
        return Result.success(service.departmentsHospitalHave(hospitalId.value));
    }
}
